
int mFactors (short int sudoku[9][9], short int missing[27][10], short int linha, short int coluna)
{
	short int fator,e=0;
	int z=0;
	for (fator=0;fator<9;fator++)
	{
		if (missing[linha][fator]==0 && missing[coluna+9][fator]==0 && missing[ddq(linha,coluna)+18][fator]==0)
		{
			z = z + (fator+1) * pow(10,e);
			e++;
		}
	}
	return z;
}

short int mCasa (short int sudoku[9][9], short int missing[27][10], short int WildCard)
{
	int nMissAtual=9, nMissAnterior=9, fator, defLinha, defColuna,z=0, linha,coluna;
	switch (WildCard)
	{
		case 0:
			for (linha=0;linha<9;linha++)
			{
				for (coluna=0;coluna<9;coluna++)
				{
					if (sudoku[linha][coluna]==0)
					{
						for (fator=0;fator<9;fator++)
						{
							if (missing[linha][fator]==1 || missing[coluna+9][fator]==1 || missing[ddq(linha,coluna)+18][fator]==1)
							{
								nMissAtual--;
							}
							if (fator==8)
							{
								if (nMissAtual<nMissAnterior)
								{
									nMissAnterior = nMissAtual;
									defLinha = linha;
									defColuna = coluna;
								}
								nMissAtual=9;
							}
						}
					}
				}
			}
			z = defLinha*100 + defColuna*10 + nMissAnterior*1;
			break;
		case 1:
			while (z==0)
			{
				linha = rand()%8;
				coluna = rand()%8;
				z = (sudoku[linha][coluna]==0) ? z+linha*100+coluna*10:z;
			}
			for (fator=0;fator<9;fator++)
			{
				if (missing[linha][fator]==1 || missing[coluna+9][fator]==1 || missing[ddq(linha,coluna)+18][fator]==1)
				{
					nMissAtual--;
				}
			}
			z = z+1*nMissAtual;
			break;
		default:
			printf("DEFAULT FUDEU\n");
			break;
	}
	return z;
}

short int randomizer (int toRandomize)
{
	int ncounter=1,randomized,randomizer;
	while (toRandomize/(int) pow(10,ncounter)!=0)
	{
		ncounter++;
	}
	randomizer = rand()%ncounter;
	randomized = (toRandomize/(int) pow(10,randomizer))%10;
	return randomized;
}